<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>文章详情</title>
  <link rel="stylesheet" href="static/common/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="static/common/bootstrap/css/bootstrap.min.css" media="all">
  <script src="static/common/jquery-3.3.1.min.js"></script>
  <style>
    *{
        list-style: none;
        margin: 0px;
        padding: 0px;
    }
    html,body{
      position: relative;
      width: 100%;
      height: 100%;
      overflow: hidden;
    }
    #searchArticle:hover{
        text-decoration: none;
    }
  </style>
</head>
<body>
<table id="article" lay-filter="article"></table>
<script type="text/html" id="global_operate">
  <a id="delete" class="layui-btn layui-btn-sm" lay-event="del" lay-filter="del" style="line-height: 30px;margin-left:34px;">彻底删除</a>
  <a id="recover" class="layui-btn layui-btn-danger layui-btn-sm" lay-filter="deleteTogabage" lay-event="deleteTogabage" style=""><object data="static/system/svg/recover.svg" type="image/svg+xml" style="position: relative;width: 20px;top: 5px;left: -3px;"></object>恢复</a>
</script>
<script type="text/html" id="sexTpl">
      <span style="color: red;">{{ d.articleTitle }}</span>
</script>
<script src="static/common/layui/layui.js"></script>
<script>
  layui.use('table', function(){
    var table = layui.table;
    
    //第一个实例
    table.render({
      elem: '#article'
      ,height: 480
      ,url: '/article_module/findGarbageArticleByPage' //数据接口
      ,page: true //开启分页
      ,toolbar: '#global_operate'//显示默认工具条
      ,limit:10
      ,totalRow: true
      ,cols: [[ //表头
        {checkbox: true}
        ,{field: 'articleId', title: '文章标识',width:'10%',sort: true,align:'center'}
        ,{field: 'articleTitle', title: '文章标题',width:'30%',align:'center',templet: '#sexTpl'}
        ,{field: 'uploadDate', title: '上传时间',width:'15%',align:'center'}
        ,{field: 'totalLove', title: '受欢迎度',width:'10%',align:'center'}
        ,{field: 'totalComment', title: '评论条数', width:'8%',align:'center'}
        // ,{field: 'userInfo', title: '文章所属',align:'center'}
        ,{field:'uName', title: '文章所属',align:'center',templet: '<div>{{d.userInfo.uName}}</div>'}
      ]]
      ,response: {
          statusName: 'status' //规定数据状态的字段名称，默认：code
          ,statusCode: 200 //规定成功的状态码，默认：0
          ,msgName: 'msg' //规定状态信息的字段名称，默认：msg
          ,dataName: 'products' //规定数据列表的字段名称，默认：data
          ,countName: 'total'
          ,limit:'limit'
      }  
    });
    table.on('checkbox(article)', function(obj){
      //文章恢复
      $('#recover').on('click',function(){
        var checkStatus = table.checkStatus('article')
        ,data = checkStatus.data;
        var ids = new Array();
        for(var i=0;i<data.length;i++){
            ids.push(data[i].articleId);
        }
          var jsonstr=JSON.stringify({'ids':String(ids),'status':'1'});
          fetch('/article_module/changeArticleStatus', {
              method: 'POST'
              ,body: jsonstr
          }).then(res => res.json()).catch(error => console.error(error))
          .then(function(response){
            if(response.status==401){
              layer.open({
                  btn:['确定']
                  ,content: response.msg
              })   
            }else if(response.status==200){
              layer.open({
                content: response.msg //这里content是一个普通的String
                ,success: function(layero, index){
                  var btn = layero.find('.layui-layer-btn');
                  btn.find('.layui-layer-btn0').on('click',function(){
                    window.location.reload();
                  })
                }
              });
            }
          });
      });
      $('#delete').on('click',function(){
        var checkStatus = table.checkStatus('article')
        ,data = checkStatus.data;
        var ids = new Array();
        for(var i=0;i<data.length;i++){
            ids.push(data[i].articleId);
        }
          var jsonstr=JSON.stringify({'ids':String(ids)});
          fetch('/article_module/deletePatchArticle', {
              method: 'DELETE'
              ,body: jsonstr
          }).then(res => res.json()).catch(error => console.error(error))
          .then(function(response){
            if(response.status==401){
              layer.open({
                  btn:['确定']
                  ,content: response.msg
              })   
            }else if(response.status==200){
              layer.open({
                content: response.msg //这里content是一个普通的String
                ,success: function(layero, index){
                  var btn = layero.find('.layui-layer-btn');
                  btn.find('.layui-layer-btn0').on('click',function(){
                    window.location.reload();
                  })
                }
              });
            }
          });
      });
  });
});
</script>
</body>
</html>